<?php
// +----------------------------------------------------------------------
// | najing [ 通用后台管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.najingquan.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: lin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\common\controller\AdminController;
use app\common\model\Setting as SettingModel;
use app\common\model\Videos as VideosModel;
use think\facade\Console;
use think\facade\Cache;
use think\facade\View;

/**
 * 平台设置
 * Class Setting
 * @package app\admin\controller
 */
class Setting extends AdminController
{
    /**
     * 平台设置
     * @author lin
     */
    public function index()
    {
        $settingModel = new SettingModel();
        if ($this->request->isAjax()) {
            foreach(input('param.') as $k => $v){
                $result = $settingModel->setValue($k, $v);
                //如果出错，就返回，如果是没有此参数，就默认跳过
                if(!$result['status'] && $result['data'] != 10008){
                    return $result;
                }
            }
            $result = array(
                'status' => true,
                'data' => [],
                'msg' => '保存成功'
            );
            //配置保存后，清理缓存
            Cache::clear();//TODO 如果开启其他缓存，记得这里要配置缓存配置信息

            Console::call('sysClear', ['--cache', '--dir']);//清除缓存文件
            Console::call('sysClear', ['--path', ROOT_PATH . 'runtime\\admin\\temp\\']); //清除模板缓存
            return $result;
        }else{
            $data = $settingModel->getAll();
            View::assign('data', $data);
            return View::fetch();
        }
    }

}